package com.sprouting.ops.controller;

import com.sprouting.ops.model.OpsKnowledgeComment;
import com.sprouting.ops.model.ResultJson;
import com.sprouting.ops.model.qo.OpsKnowledgeCommentQo;
import com.sprouting.ops.service.OpsKnowledgeCommentService;
import com.sprouting.ops.utils.CheckTool;
import com.sprouting.ops.utils.EntityTool;
import com.sprouting.ops.utils.IdTool;
import org.springframework.web.bind.annotation.*;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sprouting.ops.annotations.invoke.IdempotentSingle;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import com.sprouting.ops.interfaces.AddGroup;
import com.sprouting.ops.interfaces.UpdGroup;

/**
 * 知识库评论;(OpsKnowledgeComment)(OPS_KNOWLEDGE_COMMENT) 表控制层
 *
 * @author ：lx（长沙麓谷）
 * @date 创建时间：2025-08-21 22:45:33
 */
@Slf4j
@RestController
@RequestMapping("opsKnowledgeComment")
public class OpsKnowledgeCommentController {

    @Resource
    private OpsKnowledgeCommentService opsKnowledgeCommentService;


    /**
     * 分页查询知识库评论;
     * @param query 查询参数
     * @return
     */
    @PostMapping("getListPage")
    public ResultJson getListPage(@Validated OpsKnowledgeCommentQo query){
        if (query == null){
            query = new OpsKnowledgeCommentQo();
        }
        Page page = query.getPage();
        return ResultJson.success(opsKnowledgeCommentService.getListPage(page, query));
    }

    /**
     * 删除知识库评论;
     * @param id 知识库评论;id
     * @return
     */
    @PostMapping("delOpsKnowledgeComment")
    @IdempotentSingle
    public ResultJson delOpsKnowledgeComment(String id){
        if (CheckTool.checkNull(id)){
            return ResultJson.errorCheck();
        }

        opsKnowledgeCommentService.removeById(id);
        return ResultJson.success();
    }

    /**
     * 更新知识库评论;
     * @param bo 修改参数
     * @return
     */
    @PostMapping("updOpsKnowledgeComment")
    @IdempotentSingle
    public ResultJson updOpsKnowledgeComment(@Validated(UpdGroup.class) OpsKnowledgeComment bo){
        String msg = checkOpsKnowledgeComment(bo);
        if (msg != null){
            return ResultJson.error(msg);
        }

        EntityTool.updBase(bo);
        opsKnowledgeCommentService.updateById(bo);
        return ResultJson.success(bo);
    }

    /**
     * 保存知识库评论;
     * @param bo 保存参数
     * @return
     */
    @PostMapping("saveOpsKnowledgeComment")
    @IdempotentSingle
    public ResultJson saveOpsKnowledgeComment(@Validated(AddGroup.class) OpsKnowledgeComment bo){
        String msg = checkOpsKnowledgeComment(bo);
        if (msg != null){
            return ResultJson.error(msg);
        }

        bo.setId(IdTool.getId());
        EntityTool.saveBase(bo);
        opsKnowledgeCommentService.save(bo);
        return ResultJson.success(bo);
    }


    /**
     * 知识库评论;数据校验
     * @param bo 知识库评论; 校验数据
     * @return 非null则有错误
     */
    private String checkOpsKnowledgeComment(OpsKnowledgeComment bo){

        return null;
    }

}
